<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
    xmlns:kiwi="http://www.kiwi-project.eu/jsf"
    xmlns:c="http://java.sun.com/jstl/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:a="http://richfaces.org/a4j">


		<style>
	        .inplace{
	            border: none;
	            cursor:pointer; 
	        }
	        .hover {
	            color: #{a4jSkin.generalTextColor};
	            background-color :#{a4jSkin.tipBorderColor};
	        }   
		   
		   .typelist td {
		   		vertical-align: top;
		   }
	    </style> 
		
		<h1>Concept perspective for<h:outputText value=" "/><h:outputText property="http://www.kiwi-project.eu/kiwi/core/title"/></h1>
		
		<p style="margin-top: 20px; margin-left: 10px; margin-right: 10px;" class="help">
		  The content item currently displayed represents a SKOS concept. Using this perspective,
		  you can modify additional concept related information about the content item, i.e. broader/narrower concepts, labels, etc.
		  Note that inferred metadata is listed 
		  separately. When hovering the mouse over inferred data, an explanation justifying its existance is displayed.
		</p>

		<br/>

		<style>
			.labelColumn {
				width: 50%;
			}
		</style>

		<p:panel header="Labels" footer="The labels listed above are associated with the concept">
			<h:panelGrid columns="2" columnClasses="labelColumn,labelColumn" width="100%">
				<h:panelGroup>
					<h:form>
						<strong>Preferred Label:</strong><br/>
						<h:outputText value="#{skosService.getPreferredLabel(contentItem.resource)}"/>
						<br/>
				    	<strong>Change:</strong><br/>
						<h:inputText value="#{kiwi.core.ui.skosPerspectiveAction.prefLabel}"  />
						<p:commandButton value="Set" action="#{kiwi.core.ui.skosPerspectiveAction.changePrefLabel}" ajax="false"/>
					</h:form>
				</h:panelGroup>
				<h:panelGroup>
					<h:form>
						<strong>Alternative Labels:</strong><br/>
						<c:forEach items="#{skosService.listAlternativeLabels(contentItem.resource)}" var="label" varStatus="status">
							<h:outputText value="#{label}" />
							<h:commandLink action="#{skosService.removeAlternativeLabel(contentItem.resource,label)}">
								<h:graphicImage value="/img/type_delete.png" style="border: none;"/>
							</h:commandLink>
							<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
				    	</c:forEach>
						<br/>
				    	<strong>Add:</strong><br/>
						<h:inputText value="#{kiwi.core.ui.skosPerspectiveAction.altLabel}"  />
						<p:commandButton value="Add" action="#{kiwi.core.ui.skosPerspectiveAction.addAltLabel}" ajax="false"/>
					</h:form>
				</h:panelGroup>
			</h:panelGrid>
		</p:panel>
		
		<br/>

		<!-- list of superconcepts (needs proper layouting) -->
		<p:panel header="Broader Concepts" footer="The currently displayed item is in a skos relation with the resources listed above, or the resource listed above are in a skos:narrower relation with the current resource.">
			<h:form>
		    	<strong>Base:</strong><br/>
				<c:forEach items="#{skosService.listBroader(contentItem.resource,false)}" var="sc" varStatus="status">
		    		<h:outputLink value="#{configurationService.baseUri}/home.seam?kiwiid=#{kiwi.ui.utility.encodeURL(sc.kiwiIdentifier)}">
						<h:outputText value="#{sc.label} (#{sc.namespacePrefix})" />
					</h:outputLink>
					<h:commandLink action="#{skosService.removeBroader(contentItem.resource,sc)}">
						<h:graphicImage value="/img/type_delete.png" style="border: none;"/>
					</h:commandLink>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Inferred:</strong><br/>
				<c:forEach items="#{skosService.listBroader(contentItem.resource,true)}" var="sc" varStatus="status">
	                <s:link view="/home.xhtml" value="#{sc.label} (#{sc.namespacePrefix})"  propagation="none">
	                    <f:param name="title"/><f:param name="uri"/><f:param name="id" /><f:param name="kiwiid" value="#{sc.kiwiIdentifier}"/>
	                    <rich:toolTip attached="true" layout="block">
				            <f:facet name="defaultContent">
				                <strong>Please wait...</strong>
				            </f:facet>
	                
							<h:dataTable value="#{explanationService.explainTripleTextually(broaderTripleIds.get(sc), true)}" var="story">
							  <h:column>
			                	<h:outputText value="#{story.openingLine.body}" escape="false" style="font-weight:bold"/><h:outputText value=" #{story.openingLine.connective}" style="margin-left:5px"/>
			                	<br/>
							  	<h:dataTable value="#{story.body}" var="line">
							  		<h:column>
							  			<h:outputText value="#{line.body}" escape="false" style="font-weight:bold; margin-left:15px"/> <h:outputText value=" #{line.connective}" style="margin-left:5px"/> <br/>
							  		</h:column>
							  	</h:dataTable>
							  	<br/> <br/>
							  </h:column>
							</h:dataTable>						                
	                    </rich:toolTip>    
	                </s:link>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>			
				<br/>
		    	<strong>Add:</strong><br/>
				<p:autoComplete completeMethod="#{skosService.autocompleteConcept}"
								value="#{kiwi.core.ui.skosPerspectiveAction.selectedResource}"
				                var="resource" itemLabel="#{resource.label} (#{resource.namespacePrefix})"
								itemValue="#{resource}" forceSelection="true" converter="kiwiResourceConverter"/>
				<p:commandButton value="Add" action="#{kiwi.core.ui.skosPerspectiveAction.addBroader}" ajax="false"/>
			</h:form>
		</p:panel>
		
		<br/>

		<!-- list of subconcepts (needs proper layouting) -->
		<p:panel header="Narrower Concepts" footer="The resources listed above are in a skos:broader relation with the currently displayed item, or the current resource is in a skos:narrower relation with them.">
			<h:form>
		    	<strong>Base:</strong><br/>
		    	<c:forEach items="#{skosService.listNarrower(contentItem.resource,false)}" var="sc" varStatus="status">
		    		<h:outputLink value="#{configurationService.baseUri}/home.seam?kiwiid=#{kiwi.ui.utility.encodeURL(sc.kiwiIdentifier)}">
						<h:outputText value="#{sc.label} (#{sc.namespacePrefix})" />
					</h:outputLink>
					<h:commandLink action="#{skosService.removeNarrower(contentItem.resource,sc)}">
						<h:graphicImage value="/img/type_delete.png" style="border: none;"/>
					</h:commandLink>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Inferred:</strong><br/>
		    	<c:forEach items="#{skosService.listNarrower(contentItem.resource,true)}" var="sc" varStatus="status">
	                <s:link view="/home.xhtml" value="#{sc.label} (#{sc.namespacePrefix})"  propagation="none">
	                    <f:param name="title"/><f:param name="uri"/><f:param name="id" /><f:param name="kiwiid" value="#{sc.kiwiIdentifier}"/>
	                    <rich:toolTip attached="true" layout="block">
				            <f:facet name="defaultContent">
				                <strong>Please wait...</strong>
				            </f:facet>
	                
							<h:dataTable value="#{explanationService.explainTripleTextually(narrowerTripleIds.get(sc), true)}" var="story">
							  <h:column>
			                	<h:outputText value="#{story.openingLine.body}" escape="false" style="font-weight:bold"/><h:outputText value=" #{story.openingLine.connective}" style="margin-left:5px"/>
			                	<br/>
							  	<h:dataTable value="#{story.body}" var="line">
							  		<h:column>
							  			<h:outputText value="#{line.body}" escape="false" style="font-weight:bold; margin-left:15px"/> <h:outputText value=" #{line.connective}" style="margin-left:5px"/> <br/>
							  		</h:column>
							  	</h:dataTable>
							  	<br/> <br/>
							  </h:column>
							</h:dataTable>						                
	                    </rich:toolTip>    
	                </s:link>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Add:</strong><br/>
				<p:autoComplete completeMethod="#{skosService.autocompleteConcept}"
								value="#{kiwi.core.ui.skosPerspectiveAction.selectedResource}"
				                var="resource" itemLabel="#{resource.label} (#{resource.namespacePrefix})"
								itemValue="#{resource}" forceSelection="true" converter="kiwiResourceConverter"/>
				<p:commandButton value="Add" action="#{kiwi.core.ui.skosPerspectiveAction.addNarrower}" ajax="false"/>
			</h:form>
		</p:panel>

		<br/>

		<p:panel header="Related Concepts" footer="The resources listed above are in a skos:related relation with the currently displayed item, or the current resource is in a skos:related relation with them.">
			<h:form>
		    	<strong>Base:</strong><br/>
		    	<c:forEach items="#{skosService.listRelated(contentItem.resource,false)}" var="sc" varStatus="status">
		    		<h:outputLink value="#{configurationService.baseUri}/home.seam?kiwiid=#{kiwi.ui.utility.encodeURL(sc.kiwiIdentifier)}">
						<h:outputText value="#{sc.label} (#{sc.namespacePrefix})" />
					</h:outputLink>
					<h:commandLink action="#{skosService.removeRelated(contentItem.resource,sc)}">
						<h:graphicImage value="/img/type_delete.png" style="border: none;"/>
					</h:commandLink>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Inferred:</strong><br/>
		    	<c:forEach items="#{skosService.listRelated(contentItem.resource,true)}" var="sc" varStatus="status">
	                <s:link view="/home.xhtml" value="#{sc.label} (#{sc.namespacePrefix})"  propagation="none">
	                    <f:param name="title"/><f:param name="uri"/><f:param name="id" /><f:param name="kiwiid" value="#{sc.kiwiIdentifier}"/>
	                    <rich:toolTip attached="true" layout="block">
				            <f:facet name="defaultContent">
				                <strong>Please wait...</strong>
				            </f:facet>
	                
							<h:dataTable value="#{explanationService.explainTripleTextually(relatedTripleIds.get(sc), true)}" var="story">
							  <h:column>
			                	<h:outputText value="#{story.openingLine.body}" escape="false" style="font-weight:bold"/><h:outputText value=" #{story.openingLine.connective}" style="margin-left:5px"/>
			                	<br/>
							  	<h:dataTable value="#{story.body}" var="line">
							  		<h:column>
							  			<h:outputText value="#{line.body}" escape="false" style="font-weight:bold; margin-left:15px"/> <h:outputText value=" #{line.connective}" style="margin-left:5px"/> <br/>
							  		</h:column>
							  	</h:dataTable>
							  	<br/> <br/>
							  </h:column>
							</h:dataTable>						                
	                </rich:toolTip>    
	                </s:link>
					<c:if test="#{not status.last}">,<h:outputText value=" "/></c:if>
		    	</c:forEach>
				<br/>
		    	<strong>Add:</strong><br/>
				<p:autoComplete completeMethod="#{skosService.autocompleteConcept}"
								value="#{kiwi.core.ui.skosPerspectiveAction.selectedResource}"
				                var="resource" itemLabel="#{resource.label} (#{resource.namespacePrefix})"
								itemValue="#{resource}" forceSelection="true" converter="kiwiResourceConverter"/>
				<p:commandButton value="Add" action="#{kiwi.core.ui.skosPerspectiveAction.addRelated}" ajax="false"/>
			</h:form>
		</p:panel>
	        
</ui:composition>
